package ws.servlet;

import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;
import ws.entity.ChatInfo;

import java.io.IOException;

/**
 * @Author gjh
 * @Date 2025/9/18
 * @Description:
 */
@WebServlet(urlPatterns = "/login")
public class LoginServlet extends HttpServlet {

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String user = req.getParameter("user");
        HttpSession session = req.getSession();
        ChatInfo chatInfo = new ChatInfo(user);
        // 保存到 HttpSession 中
        session.setAttribute("chatInfo", chatInfo);
        //转发到聊天页面
        req.getRequestDispatcher("/WEB-INF/index.html").forward(req,resp);
    }
}